Skip to content

feat(audit_log): let ExApps write to the admin audit log - #1219

Open
kyteinsky wants to merge 4 commits into
mainfrom
feat/ex-app-audit-logs
Open

kyteinsky wants to merge 4 commits into
mainfrom
feat/ex-app-audit-logs

Conversation

@kyteinsky

@kyteinsky kyteinsky commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

ExApps had no way to record admin or security relevant actions in the admin audit log; the existing log endpoint only writes to nextcloud.log. The operation must start with the ID of the calling ExApp, so an ExApp cannot write entries that look like they came from Nextcloud or another app, and every entry names the ExApp in its appId parameter.

Assisted-by: Copilot:claude-opus-5-5

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI (N/A)

ExApps had no way to record admin or security relevant actions in the admin audit log; the
existing log endpoint only writes to nextcloud.log. The operation must start with the ID of
the calling ExApp, so an ExApp cannot write entries that look like they came from Nextcloud
or another app, and every entry names the ExApp in its appId parameter.

Assisted-by: Copilot:claude-opus-5-5
Signed-off-by: Anupam Kumar <kyteinsky@gmail.com>
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds ExApp audit-log entry validation and dispatch, exposes a POST /api/v1/audit_log OCS endpoint, and documents the endpoint in both OpenAPI documents. Tests cover successful dispatch and several invalid-entry cases.

Merge Risk: Moderate · up to 6ca30

The ExApp audit-log endpoint is new, so the blast radius is limited to ExApps that call it. Two open concerns should be settled before merge: whether message formatting can drop the app attribution from stored audit entries, and whether the OpenAPI schema rejects null parameter values that the runtime accepts.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: ExApps can now write entries to the admin audit log via a new endpoint. It matches the audit logger method, the OCS route, and the controller changes in the changeset.…
Description check Passed The description states the problem (ExApps cannot record admin or security actions in the admin audit log) and explains the design choice (operation must start with the calling ExApp ID and each entry…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: ExApps can now write entries to the admin audit log via a new endpoint. It matches the audit logger method, the OCS route, and the controller changes in the changeset. The title is specific and scoped to the feature.

Full details: Description check

Explanation

The description states the problem (ExApps cannot record admin or security actions in the admin audit log) and explains the design choice (operation must start with the calling ExApp ID and each entry names the ExApp in appId). This matches the logForExApp and auditLog changes.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 27f85065-dabc-4e2e-803c-d95f8f4c5f14
Commits

Reviewing files that changed from the base of the PR and between b397fb1 and 6ca304b.

Files selected for processing: 2

  • lib/AuditLog/AuditLogger.php
  • tests/php/AuditLog/AuditLoggerTest.php

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f313c5a1-2d3c-4437-ba21-db3b2de86d42
Commits

Reviewing files that changed from the base of the PR and between 634729d and 3cb52bd.

Files selected for processing: 6

  • appinfo/routes.php
  • lib/AuditLog/AuditLogger.php
  • lib/Controller/OCSApiController.php
  • openapi-full.json
  • openapi.json
  • tests/php/AuditLog/AuditLoggerTest.php

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Comment thread lib/AuditLog/AuditLogger.php Resolved
Comment thread openapi-full.json
"default": {},
"description": "Named values for the placeholders of the message, optionally followed by more context",
"additionalProperties": {
"nullable": true,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Data Integrity & Integration · Quick win

Make null valid in a typed schema branch.

The logger accepts parameters={"item":null}, but this schema rejects it. In OpenAPI 3.0.3, nullable needs type in the same Schema Object. None of these anyOf branches permits null. (spec.openapis.org)

Move nullable: true into a typed branch, such as the string branch. Keep the other scalar branches. Correct the generator output and regenerate both OpenAPI documents.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a10ea4bd-eba6-41cf-b8fd-1ce7ff421f7d
Commits

Reviewing files that changed from the base of the PR and between 3cb52bd and b397fb1.

Files selected for processing: 4

  • appinfo/routes.php
  • lib/AuditLog/AuditLogger.php
  • lib/Controller/OCSApiController.php
  • tests/php/AuditLog/AuditLoggerTest.php

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Comment thread lib/AuditLog/AuditLogger.php Resolved
An ExApp could use %c to write braces into the message after the escaping, which let it add
placeholders such as {params} that the logger then filled in, dropping the appId from the stored
entry. A large width such as %1073741824s made vsprintf exhaust the memory of the request.
ExApp messages now only accept %s and %%, and the formatted message is escaped as a whole.

Assisted-by: Copilot:claude-opus-5-5
Signed-off-by: Anupam Kumar <kyteinsky@gmail.com>
…ameters

The appId parameter is added before formatting, so a message with exactly one placeholder too
many took the app ID as its last value instead of being rejected, and the entry read for example
"a test_app" instead of naming the missing value.

Assisted-by: Copilot:claude-opus-5-5
Signed-off-by: Anupam Kumar <kyteinsky@gmail.com>

@oleksandr-nc oleksandr-nc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on NC 36 with this branch merged onto main: unit tests, cs and psalm pass, and 20 live calls to the endpoint behave as documented (valid entries are correct, every invalid case gets 400).

  • Please add a CHANGELOG line under [Unreleased] / Added.
  • The endpoint needs a docs follow-up in developer_manual/exapp_development/tech_details/api/logging.rst.
  • Optional: there is no size limit, a 1 MB parameter was accepted and written twice (message and params).

if ($appId === '') {
throw new InvalidArgumentException('App ID must not be empty');
}
if (!str_starts_with($operation, $appId . '.')) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExApp IDs may contain - (app-skeleton-python, our test-deploy), but CriticalActionPerformedEvent only accepts [a-z][a-z0-9_]* parts, so such an ExApp gets 400 for any operation, with or without the hyphen (checked live). Accepting the ID with - replaced by _ as the prefix would fix it; appId still names the real app.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, nice catch!
perhaps we should make the change in the server so the value isn't misrepresented and the appId remains exactly what it is?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants